package com.kiln.juxingqs.utils;

import com.blankj.utilcode.util.LogUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class DateUtils {

    /**
     * 判断当前时间是否在某一时间段内（eg：06:00~22:00）
     *
     * @param beginTimeStr
     * @param endTimeStr
     */
    public static Boolean isBelong(String beginTimeStr, String endTimeStr) {
//        Boolean is_belong = false;

        SimpleDateFormat df = new SimpleDateFormat("HH:mm", Locale.CHINA);//设置日期格式
        String now = null;
        try {
            now = df.format(new Date());

            if (now.compareTo(beginTimeStr) > 0 && now.compareTo(endTimeStr) < 0) return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
//        LogUtils.i(beginTime +" <<< beginTime");
        return false;
    }


    /**
     * 判断时间是否在时间段内
     *
     * @param nowTime
     * @param beginTime
     * @param endTime
     * @return
     */
    public static boolean belongCalendar(Date nowTime, Date beginTime, Date endTime) {
        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);

        Calendar begin = Calendar.getInstance();
        begin.setTime(beginTime);

        Calendar end = Calendar.getInstance();
        end.setTime(endTime);

        if (date.after(begin) && date.before(end)) {
            return true;
        } else {
            return false;
        }
    }

}
